package hd.util.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;

import hd.util.app.BaseContext;

/**
 * Base
 * <p/>
 * Created by haidy on 14/12/6.
 */
public class BaseActivity extends Activity {

    public BaseContext app;
    public static boolean isRunning = false;
    public boolean isLoading = false;

    public View view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void hindActionBar() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }

    @Override
    protected void onResume() {
        super.onResume();
        isRunning = true;
    }

    @Override
    protected void onPause() {
        super.onPause();
        isRunning = false;
    }

    /**
     * 关闭输入框
     */
    public void closeInputMethod() {
        try {
            InputMethodManager inputMethodManager = (InputMethodManager) getBaseContext().getSystemService(INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        } catch (Exception ignored) {
        }
    }

    /**
     * 弹出输入法
     *
     * @param view 请求的View
     */
    public void openInputMethod(View view) {
        view.requestFocus();
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        inputMethodManager.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
    }
}